package com.D5Power.Editor.EditorWindow
{
	import com.D5Power.Editor.LuaEditor;
	import com.D5Power.Editor.Objects.NCharacterObject_MaEd;
	import com.D5Power.Objects.GameObject;
	import com.D5Power.Objects.NCharacterObject;
	
	import flash.events.Event;
	
	import org.aswing.JButton;
	import org.aswing.JLabel;
	import org.aswing.JTextField;
	import org.aswing.ext.Form;
	
	public class NPCAttr extends ObjectAttr
	{
		private var _lua_name:JTextField;
		private var _name:JTextField;
		private var _uid:JTextField;
		
		/**
		 * @param	owner	主程序映射
		 * @param	obj		控制对象
		 */ 
		public function NPCAttr(owner:MapEditor, obj:GameObject=null)
		{
			mytitle='NPC属性';
			super(owner, obj);
		}
		
		override protected function init():void
		{
			_box = new Form();
			
			// 姓名编辑
			_name = new JTextField((_obj as NCharacterObject_MaEd).username,10);
			var lable:JLabel = new JLabel('姓名：',null,JLabel.LEFT);
			
			// UID编辑
			_uid = new JTextField((_obj as NCharacterObject_MaEd).uid.toString(),10);
			var lable2:JLabel = new JLabel('UID：',null,JLabel.LEFT);

			_box.addRow(lable,_name);
			_box.addRow(lable2,_uid);
			
			_box.setSizeWH(200,200);
			getContentPane().append(_box);
			super.init();
		}
		
		override protected function onSubmit(e:Event):void
		{
			(_obj as NCharacterObject).setName(_name.getText());
			(_obj as NCharacterObject).uid = int(_uid.getText());
			super.onSubmit(e);
		}
		
		/**
		 * 提供给LuaEditor调用的保存后的返回函数
		 * @param	s	保存后的文件名
		 */ 
		public function luaEditorBack(s:String):void
		{
			_lua_name.setText(s);
			TrueObj.lua_filename=s;
		}
		
		private function editLua(e:Event):void
		{
			var editor:LuaEditor = new LuaEditor(_root.Window,_lua_name.getText(),_obj,this);
			editor.show();
		}
		
		private function get TrueObj():NCharacterObject
		{
			return _obj as NCharacterObject;
		}
	}
}